package com.zsj.stack;

/**
 * @Author zsj
 * @Version 1.0
 * @Date 2024/3/25 14:48
 * @Description 双端栈模拟队列 力扣232
 */
public class StackToQueueLeetCodeQuestion {

    ArrayStack<Integer> left = new ArrayStack<>(100);//左
    ArrayStack<Integer> right = new ArrayStack<>(100);//右

    //双端栈模拟队列的思想
    /*
    应该就是 右边用来加元素 左边用来弹元素
     */

    /**
     * 向队尾插入元素
     *
     * @param x
     */
    public void push(int x) {
        right.push(x);
    }

    /**
     * 弹出队首元素
     *
     * @return
     */
    public int pop() {
        if (left.isEmpty()) {
            while (!right.isEmpty()) {
                Integer pop = right.pop();
                left.push(pop);
            }
        }
        return left.pop();
    }

    /**
     * 查看队首元素
     *
     * @return
     */
    public int peek() {
        if (left.isEmpty()) {
            while (!right.isEmpty()) {
                Integer pop = right.pop();
                left.push(pop);
            }
        }
        return left.peak();
    }

    /**
     * 队列为空
     *
     * @return
     */
    public boolean empty() {
        return left.isEmpty() && right.isEmpty();
    }
}
